package cn.iocoder.yudao.module.alipay.controller.admin.alipaypermission;


import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.alipay.service.alipermission.AliPayService;
import com.alipay.api.AlipayApiException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Map;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 支付宝api")
@RestController
@RequestMapping("/alipay/mini-program/")
@Validated
public class AliPayAdminController {


    @Resource
    private AliPayService aliPayService;

    /**
     * (支付宝) 换取授权访问令牌
     * @param grantType 必选 授权方式
     * @param code 可选 授权码
     * @return
     */
    @GetMapping("/getAppAuthTokenByCode")
    @Operation(summary = "换取应用授权令牌")
    public CommonResult<Map> getAppAuthTokenByCode(String grantType,String code) throws AlipayApiException {
        return success(aliPayService.getAppAuthTokenByCode(grantType,code));
    }

    /**
     * (支付宝) 上传应用版本
     * @return
     */
    @GetMapping("/uploadAppVersion")
    @Operation(summary = "上传应用版本")
    public CommonResult<Object> uploadAppVersion(@RequestParam("authAppId")String authAppId) throws AlipayApiException {
        return success(aliPayService.uploadAppVersion(authAppId));
    }

    /**`
     * (支付宝) 提交审核
     * @return`
     */
    @GetMapping("/auditAppVersion")
    @Operation(summary = "提交审核")
    public CommonResult<Object> auditAppVersion(@RequestParam("authAppId")String authAppId) throws AlipayApiException {
        return success(aliPayService.auditAppVersion(authAppId));
    }

    /**`
     * (支付宝) 查询小程序版本
     * @return`
     */
    @GetMapping("/queryAppVersion")
    @Operation(summary = "提交审核")
    public CommonResult<Object> queryAppVersion(@RequestParam("authAppId")String authAppId) throws AlipayApiException {
        return success(aliPayService.queryAppVersion(authAppId));
    }

    /**`
     * (支付宝) 删除版本
     * @return`
     */
    @GetMapping("/delAppVersion")
    @Operation(summary = "删除版本")
    public CommonResult<Object> delAppVersion(@RequestParam("authAppId")String authAppId) throws AlipayApiException {
        return success(aliPayService.delAppVersion(authAppId));
    }

    /**`
     * (支付宝) 撤销审核
     * @return`
     */
    @GetMapping("/cancleAppVersion")
    @Operation(summary = "撤销审核")
    public CommonResult<Object> cancleAppVersion(@RequestParam("authAppId")String authAppId) throws AlipayApiException {
        return success(aliPayService.cancleAppVersion(authAppId));
    }



    /**
     * (支付宝) 上架小程序
     * @return
     */
    @GetMapping("/onlineAppVersion")
    @Operation(summary = "上架小程序")
    public CommonResult<Object> onlineAppVersion(@RequestParam("authAppId")String authAppId) throws AlipayApiException {
        return success(aliPayService.onlineAppVersion(authAppId));
    }


    /**
     * (支付宝) 下架版本
     * @return
     */
    @GetMapping("/offlineAppVersion")
    @Operation(summary = "下架版本")
    public CommonResult<Object> offlineAppVersion(@RequestParam("authAppId")String authAppId) throws AlipayApiException {
        return success(aliPayService.offlineAppVersion(authAppId));
    }

    /**
     * (支付宝) 下架版本
     * @return
     */
    @GetMapping("/isPassedAppVersion")
    @Operation(summary = "查询版本审核是否通过")
    public CommonResult<Object> isPassedAppVersion(@RequestParam("authAppId")String authAppId) throws AlipayApiException {
        return success(aliPayService.isPassedAppVersion(authAppId));
    }


}
